﻿package com.vfd.xml {
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	/**
	* Loads an XML document and dispatches and event on load. Saves the trouble of having to
	* instantitate the URL load and request repeatedly for loading xml documents.
	* @author Jeremy Wischusen <cortex@visualflowdesigns.com>
	*/
	public class XMLLoader extends EventDispatcher {
		public static const XML_LOADED:String = 'xmlLoaded';
		private var _loader:URLLoader; 
		private var _request:URLRequest; 
		private var _xml:XML;
		public function XMLLoader() {
			this._loader = new URLLoader(); 
			this._request = new URLRequest(); 
			this._loader.addEventListener(Event.COMPLETE, onLoaded)
		}
		public function load(path:String):void {
			this._request.url = path;
			this._loader.load(this._request); 
		}
		private function onLoaded(e:Event):void {
			this._xml  = XML(e.target.data); 
			this.dispatchEvent(new Event(XML_LOADED));
		}
		public function get xml(): XML {
			return this._xml;
		}
		
	}
	
}